package cn.snmp.mutual.uk.stack;

import cn.snmp.mutual.uk.util.SnmpUtilities;

import java.io.*;

class AsnDecoderv2c extends AsnDecoderBase {
    private static final String version_id = "@(#)$Id: AsnDecoderv2c.java,v 3.3 2006/02/09 14:16:36 birgit Exp $ Copyright Westhawk Ltd";

    AsnPduSequence DecodeSNMPv2c(final InputStream in, final String community) throws IOException, DecodingException {
        final AsnSequence asnTopSeq = this.getAsnSequence(in);
        final int snmpVersion = this.getSNMPVersion(asnTopSeq);
        if (snmpVersion != 1) {
            final String str = SnmpUtilities.getSnmpVersionString(snmpVersion);
            final String msg = "Wrong SNMP version: expected SNMPv2c, received " + str;
            throw new DecodingException(msg);
        }
        final String comm = this.getCommunity(asnTopSeq);
        if (!comm.equals(community)) {
            final String msg = "Wrong community: expected " + community + ", received " + comm;
            throw new DecodingException(msg);
        }
        final AsnPduSequence Pdu = (AsnPduSequence) asnTopSeq.findPdu();
        return Pdu;
    }
}
